import {
	mapMutations
} from 'vuex'

export default {
	...mapMutations([
		'upIndexInfo',
	]),
	select(index) {
		this.current = index;
		this.page = 1;
		this.list = [];
		this.getChannelList();
	},
	getPageList() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'wechat/getAllChannel',
			method: 'get',
			params: {},
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.tabList = res.data
					that.getChannelList();
				} else {

				}
			}
		}, false)
	},
	getChannelList() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'wechat/getChannelInformationList',
			method: 'get',
			params: {
				channelId: that.tabList[that.current].id,
				pageNo: that.page,
				pageSize: that.list_rows,
			},
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					console.log(res.data)
					if (that.page === 1) {
						that.list = res.data.rows
					} else {
						that.list = that.list.concat(res.data.rows)
					}
					that.page++
				} else {

				}
			}
		}, false)
	},
	changeFavoriteInformation(item, id) {
		let url = !item.favorite ? 'wechat/favoriteInformation' : 'wechat/cancelFavoriteInformation'
		let that = this
		that.$httpRequest.request({
			that: that,
			url,
			method: 'post',
			params: {
				informationId: id
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (item.favorite) {
						item.favoriteCount--
					} else {
						item.favoriteCount++
					}

					item.favorite = !item.favorite

				} else {
					that.$toast.msg(res.message, {
						icon: 1
					})
				}
			}
		})
	},
	//收藏
	changeCollectInformation(item, id) {
		let url = !item.collect ? 'wechat/collectInformation' : 'wechat/cancelCollectInformation'
		let that = this
		that.$httpRequest.request({
			that: that,
			url,
			method: 'post',
			params: {
				informationId: id
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (item.collect) {
						item.collectCount--
					} else {
						item.collectCount++
					}

					item.collect = !item.collect

				} else {
					that.$toast.msg(res.message, {
						icon: 1
					})
				}
			}
		})
	},
}